#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    srand((time_t)time(nullptr));

    QPushButton* button = new QPushButton(this);
    button->setText("button");
    connect(button, &QPushButton::clicked, this, &Widget::handler);

    this->setWindowTitle("this is a title");
    button->setWindowTitle("what will happen?");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::handler()
{
    QRect rectNoFrame = this->geometry();
    QRect rectFrame = this->frameGeometry();
    qDebug() << "rectNoFrame: " << rectNoFrame;
    qDebug() << "rectFrame: " << rectFrame;
}

void Widget::on_pushButton_fire_clicked()
{
    ui->label->setText("开始播放: 一等情事...");
}


void Widget::on_pushButton_sacrifice_pressed()
{
    int widgetWidth = this->geometry().width();
    int widgetHeight = this->geometry().height();
    int pushButtonWidth = ui->pushButton_sacrifice->geometry().width();
    int pushButtonHeight = ui->pushButton_sacrifice->geometry().height();
    ui->pushButton_sacrifice->setGeometry (
            rand() % (widgetWidth - pushButtonWidth),
            rand() % (widgetHeight - pushButtonHeight),
            pushButtonWidth, pushButtonHeight
        );
}

